﻿
using System;

namespace OestsCommon.Model
{
    public class User
    {
        /// <summary>
        /// 数据库ID
        /// </summary>
        public int DBid { get; set; }

        /// <summary>
        /// 工号，包含：字母 _ 数字
        /// </summary>
        public string Number { get; set; }

        /// <summary>
        /// 姓名 长度要求小于10
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 密码
        /// </summary>
        public string Password { get; set; }

        /// <summary>
        /// 用户类型
        /// </summary>
        public UserType Type { get; set; }

        /// <summary>
        /// 身份证号
        /// </summary>
        public string IdNo { get; set; }

        /// <summary>
        /// 登录时间
        /// </summary>
        public DateTime LoginTime { get; set; }

        /// <summary>
        /// 该值会实时的刷新，保证异常退出时也会记录一个最近的值
        /// </summary>
        public DateTime LogoutTime { get; set; }

        public User()
        {
            Number = "";
            Name = "";
            Password = "";
            Type = UserType.None;
            DBid = -1;
        }

        public User(string number, string pwd)
        {
            Number = number;
            Password = pwd;
        }

        /// <summary>
        /// 计算在线时长
        /// </summary>
        /// <returns></returns>
        public string CalculationOnlineTime()
        {
            if (LoginTime == null || LogoutTime == null) return "0";
            TimeSpan ts = LogoutTime.Subtract(LoginTime);
            double hours = ts.Hours;//24.0
            double minutes = ts.Minutes;//60.0
            double seconds = ts.Seconds;//60.0
            return string.Format("{0}小时{1}分钟{2}秒", hours, minutes, seconds);
        }
    }

}
